package io.renren.controller;

import io.renren.annotation.Login;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.service.BalanceDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

/**
 * 资金流水接口
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-03-23 15:31
 */
@RestController
@RequestMapping("/api/accounting")
@Api(tags = "流水接口")
public class ApiAccountingController extends AbstractController {

	@Autowired
	private BalanceDetailService balanceDetailService;

	@Login
	@PostMapping("buyList")
	@ApiOperation("买入列表")
	public R buyList(@ApiIgnore @RequestAttribute("userId") Long userId, @ApiIgnore @RequestParam Map<String, Object> params) {
		params.put("category", 0);
		params.put("id", userId);
		PageUtils page = balanceDetailService.queryPage(params);
		return R.ok().put("page", page);
	}

	@Login
	@PostMapping("sellList")
	@ApiOperation("卖出列表")
	public R sellList(@ApiIgnore @RequestAttribute("userId") Long userId, @ApiIgnore @RequestParam Map<String, Object> params) {
		params.put("category", 1);
		params.put("id", userId);
		PageUtils page = balanceDetailService.queryPage(params);
		return R.ok().put("page", page);
	}

	@Login
	@PostMapping("profitList")
	@ApiOperation("收益列表")
	public R profitList(@ApiIgnore @RequestAttribute("userId") Long userId, @ApiIgnore @RequestParam Map<String, Object> params) {
		params.put("category", 2);
		params.put("id", userId);
		PageUtils page = balanceDetailService.queryPage(params);
		return R.ok().put("page", page);
	}

	@Login
	@PostMapping("rewardList")
	@ApiOperation("奖励列表")
	public R rewardList(@ApiIgnore @RequestAttribute("userId") Long userId, @ApiIgnore @RequestParam Map<String, Object> params) {
		params.put("category", 3);
		params.put("id", userId);
		PageUtils page = balanceDetailService.queryPage(params);
		return R.ok().put("page", page);
	}
}
